********************************************************************************
**  TITLE:      il2009_ines_contact_networks                                  **  
**  AUTHOR:	    Philippe Mongrain                                             **
**  DATA:       2009                                                          **
**	DATE:		October 2022 					                              **	
**  VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "il2009_ines_contact_networks", replace

* Open the dataset

use "2009.dta", clear 


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen sdate = .

replace sdate = 20090115 if day == 15 & month == 1
replace sdate = 20090118 if day == 18 & month == 1
replace sdate = 20090119 if day == 19 & month == 1
replace sdate = 20090120 if day == 20 & month == 1
replace sdate = 20090121 if day == 21 & month == 1
replace sdate = 20090122 if day == 22 & month == 1
replace sdate = 20090123 if day == 23 & month == 1
replace sdate = 20090124 if day == 24 & month == 1
replace sdate = 20090155 if day == 25 & month == 1
replace sdate = 20090126 if day == 26 & month == 1
replace sdate = 20090127 if day == 27 & month == 1
replace sdate = 20090128 if day == 28 & month == 1
replace sdate = 20090129 if day == 29 & month == 1
replace sdate = 20090201 if day == 1 & month == 2
replace sdate = 20090202 if day == 2 & month == 2
replace sdate = 20090203 if day == 3 & month == 2
replace sdate = 20090204 if day == 4 & month == 2
replace sdate = 20090205 if day == 5 & month == 2

gen surveydate=date(string(sdate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY surveydate

gen edate = 20090210

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = electiondate - surveydate

* Gender

gen male = sex_1

recode male (2=0)

* Age

gen age = age_1

replace age = . if age < 17

* Education

gen education = v181_1

* Prime minister vote intention (hypothetical)

gen pmvote = .

replace pmvote = 9999 if v156 == .
replace pmvote = 9999 if v156 == 8

replace pmvote = 1 if v156 == 2 & pmvote!=9999

replace pmvote = 0 if v156!=2 & pmvote!=1 & pmvote!=9999

replace pmvote = . if pmvote == 9999

label define pmvote 0 "Loser PM vote" 1 "Winner PM vote"
label values pmvote pmvote

* Care about PM outcome

gen carepm = v161

recode carepm (9=.)

replace carepm = 5 - carepm

* Press news attentiveness

gen press = v136

recode press (5=4)
recode press (8=.)

recode press (.=-99)

* TV news attentiveness

gen tv = v137

recode tv (5=4)
recode tv (8=.)

recode tv (.=-99)

* Election broadcast news attentiveness

gen broadcast = v139

recode broadcast (9=.)

replace broadcast = 6 - broadcast

recode broadcast (.=-99)

* News attentiveness index

egen news = rowmax(press tv broadcast)

recode news (-99=.)

* Minimum threshold for representation in elections to the Knesset - Correct answers (2%) = 1, Incorrect answer = 0

gen threshold = v172

recode threshold (9=.)

replace threshold = 0 if threshold!=1 // Incorrect answer
replace threshold = 1 if threshold == 1 // Correct answer

* Percentage of the overall government budget for security - Correct answers (between 10% and 40%) = 1, Incorrect answer = 0

gen security = v173

recode security (9=.)

replace security = 0 if security!=2 & security!=. // Incorrect answer
replace security = 1 if security == 2 // Correct answer

* Knesset Speaker - Correct answers (Dalya Itzik) = 1, Incorrect answer = 0

gen speaker = v174

recode speaker (9=.)

replace speaker = 0 if speaker!=1 & speaker!=. // Incorrect answer
replace speaker = 1 if speaker == 1 // Correct answer

* Political knowledge index

gen knowledge = threshold + security + speaker

* Political discussion

gen discussion = v55

recode discussion (9=.)

replace discussion = 4 - discussion

gen discussion_3pts = discussion
replace discussion_3pts = 0 if discussion == 1
replace discussion_3pts = 1 if discussion == 2
replace discussion_3pts = 2 if discussion == 3


*********************************
** NATIONAL-LEVEL EXPECTATIONS ** 
*********************************

* Generate variable identifying incomplete answers

gen tzipi = v158
gen netanyahu = v159
gen barak = v160

gen complete_whole = 1 if tzipi!=. & netanyahu!=. & barak!=.

* Generate value of 1 if the expectation for one coalition is higher or equal to the expectations for at least one other coalition

gen pmA = 1 if tzipi >= netanyahu & tzipi >= barak & complete_whole == 1

gen pmB = 1 if netanyahu >= tzipi & netanyahu >= barak & complete_whole == 1

gen pmC = 1 if barak >= tzipi & barak >= netanyahu & complete_whole == 1

gen pmOTH = 1 if tzipi == 0 & netanyahu == 0 & barak == 0 & complete_whole == 1

replace pmA = . if pmOTH == 1 & complete_whole == 1
replace pmB = . if pmOTH == 1 & complete_whole == 1
replace pmC = . if pmOTH == 1 & complete_whole == 1

* Generate variable for ambiguous forecasts

gen ambiguous_whole = .

replace ambiguous_whole = 99 if pmA == pmB & pmA!=. | pmA == pmC & pmA!=.

replace ambiguous_whole = 99 if pmB == pmA & pmB!=. | pmB == pmC & pmB!=.

replace ambiguous_whole = 99 if pmC == pmA & pmC!=. | pmC == pmB & pmC!=.

* Generate value of 0 for lower expectations

replace pmA = 0 if pmA!=1 & pmA!=. & complete_whole == 1
replace pmB = 0 if pmB!=1 & pmB!=. & complete_whole == 1
replace pmC = 0 if pmC!=1 & pmC!=. & complete_whole == 1
replace pmOTH = 0 if pmOTH!=1 & pmOTH!=. & complete_whole == 1

* Forecasts (1 = Livni, 2 = Netanyahu, 3 = Barak, 88 = other, 99 = ambiguous)

gen forecast_whole = .

replace forecast_whole = 1 if pmA == 1 & complete_whole == 1
replace forecast_whole = 2 if pmB == 1 & complete_whole == 1
replace forecast_whole = 3 if pmC == 1 & complete_whole == 1
replace forecast_whole = 88 if pmOTH == 1 & complete_whole == 1
replace forecast_whole = 99 if ambiguous_whole == 1 & complete_whole == 1

* Identify correct and ambiguous forecasts

gen correct_whole = 0 if forecast_whole!=2 & forecast_whole!=. & complete_whole == 1
replace correct_whole = 1 if forecast_whole == 2 & complete_whole == 1

replace correct_whole = 99 if forecast_whole == 99 & pmB == 1 & complete_whole == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_whole_d = correct_whole

replace correct_whole_d = 0 if correct_whole_d == 99
replace correct_whole_d = 1 if correct_whole_d == 1


**********
** SAVE **
**********

save "il2009_ines.dta", replace


********************
** MAIN ANALAYSES **
********************

* Regression analysis and percentage of correct and incorrect forecasts

logistic correct_whole_d discussion i.pmvote news knowledge carepm age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Prime minister (DV)"
label variable discussion "Discussion"
label variable pmvote "PM vote"
label variable news "News attentiveness"
label variable knowledge "Political knowledge"
label variable carepm "Caring about outcome"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"

estpost tabstat correct_whole_d discussion pmvote news knowledge carepm age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "il2009_ines_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2009 Israeli legislative election (INES), national level") replace

eststo clear

log close